package com.bootdo.appsystem.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bootdo.app.utils.redis.AppRedisUtil;
import com.bootdo.app.utils.returnresponse.ServerResponse;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.appsystem.domain.RegectDO;
import com.bootdo.appsystem.service.RegectService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 
 * 
 * @author xiaoxiao
 * @email 806191255@qq.com
 * @date 2018-05-12 14:42:14
 */
 
@Controller
@RequestMapping("/appsystem/regect")
public class RegectController {
	@Autowired
	private RegectService regectService;

	
	@GetMapping()
	@RequiresPermissions("appsystem:regect:regect")
	String Regect(){
	    return "appsystem/regect/regect";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("appsystem:regect:regect")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<RegectDO> regectList = regectService.list(query);
		int total = regectService.count(query);
		PageUtils pageUtils = new PageUtils(regectList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("appsystem:regect:add")
	String add(){
	    return "appsystem/regect/add";
	}

	@GetMapping("/edit/{regionId}")
	@RequiresPermissions("appsystem:regect:edit")
	String edit(@PathVariable("regionId") Double regionId,Model model){
		RegectDO regect = regectService.get(regionId);
		model.addAttribute("regect", regect);
	    return "appsystem/regect/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("appsystem:regect:add")
	public R save( RegectDO regect){
		if(regectService.save(regect)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("appsystem:regect:edit")
	public R update( RegectDO regect){
		regectService.update(regect);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("appsystem:regect:remove")
	public R remove( Double regionId){
		if(regectService.remove(regionId)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("appsystem:regect:batchRemove")
	public R remove(@RequestParam("ids[]") Double[] regionIds){
		regectService.batchRemove(regionIds);
		return R.ok();
	}

	/**
	 *【@author】  @fan
	 *【方法解释】 三级联动获取city数据
	 *【@date】    2018/5/13 0013  下午 17:01
	 */
	@ResponseBody
	@PostMapping("creatcity")
	public ServerResponse<List<RegectDO>> creatCity(Double parantid){
		return regectService.creatCity(parantid);
	}

	
}
